package com.hello.sky.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hello.sky.mapper.SetmealDishMapper;
import com.hello.sky.model.entity.SetmealDish;
import com.hello.sky.service.SetmealDishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 套餐菜品关系 服务实现类
 * </p>
 *
 * @author D
 */
@Slf4j
@Service
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish> implements SetmealDishService {

    @Transactional
    @Override
    public void updateBySetmealId(Long setmealId, List<SetmealDish> dishList) {
        //先删
        baseMapper.delBySetmealId(setmealId);
        //再插
        if (dishList == null || !(dishList.size() > 0)) return;
        dishList.forEach(setmealDish -> setmealDish.setSetmealId(setmealId));
        baseMapper.addBatch(dishList);
    }
}
